<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Answer</title>
    <style>
        #MainBox {
            flex: 1;
            text-align: center;
            width: 100%;
            height: 50px;
            margin-top: 200px;
        }

        #btnBox {
            width: 360px;
            height: auto;
            margin: 5px auto;
        }

        #getAnswer {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            font-size: 32px;
        }
    </style>
    <!-- 引入layui css -->
    <link href="https://www.layuicdn.com/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <!-- 引入layui js -->
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
</head>
<body>
<div id="MainBox">
    <div id="btnBox">
        <button class="layui-btn" id="getAnswer" onclick="f()">点击抢答</button>
    </div>
</div>

<script>

    function f() {
        $.ajax({
            method: 'GET',
            url: '/studentRob/stuRob',
            success: (res) => {
                alert(res.message);
            },
            complete: function (xhr) {
                if ("REDIRECT" === xhr.getResponseHeader("REDIRECT")) {
                    alert("登陆时间过长，请重新登陆!");
                    window.location.href = xhr.getResponseHeader("CONTENTPATH");
                }
            }
        })
    }

    window.onload = () => {
        $.ajax({
            type: "GET",
            url: "/user/userStatus",
            async: false,
            success: (userInfo) => {
                // console.log(userInfo)
                if (!(userInfo.status)) {
                    alert('登陆失效，请重新登录！')
                    window.location.href = '/';
                }
            }
        })
        $.ajax({
            type: "GET",
            url: "/studentRob/getStatus",
            async: false,
            success: (res) => {
                if (!res.status) {
                    alert("未开始抢答");
                }
            },
            complete: function (xhr) {
                if ("REDIRECT" === xhr.getResponseHeader("REDIRECT")) {
                    alert("登陆时间过长，请重新登陆!");
                    window.location.href = xhr.getResponseHeader("CONTENTPATH");
                }
            }
        })
    }
</script>

</body>
</html>